import time
import json
import re
import pandas as pd
from iotdb.dbapi import connect
import pymysql
import os,sys

class DATA_JSON:
    def __init__(self):
        self.dirs = os.listdir(f"./top_100_metrics")

    def dir_json(self,i):
        dir = os.listdir(f"./top_100_metrics/{self.dirs[i]}")
        goal = f"./top_100_metrics/{self.dirs[i]}/{dir[0]}"
        table = re.sub(r'[^a-zA-Z0-9_]', '_', self.dirs[i])
        return table,goal


class DB_IOTDB:
    def __init__(self):
        self.iotdb_ip = "127.0.0.1"
        self.iotdb_port = "6667"
        self.iotdb_username = "root"
        self.iotdb_password = "root"

    def iotdb(self):

        self.conn = connect(
            self.iotdb_ip,
            self.iotdb_port,
            self.iotdb_username,
            self.iotdb_password,
            fetch_size=1024,
            zone_id="UTC+8",
            sqlalchemy_mode=False
        )


class DB_MYSQL:
    def __init__(self):
        self.mysql_host = "127.0.0.1"
        self.mysql_port = 3306
        self.mysql_username = "root"
        self.mysql_password = "123456"
        self.database="opendigger"

    def Connect(self):
        self.con = pymysql.connect(
            host=self.mysql_host,
            port = self.mysql_port,
            user = self.mysql_username,
            password = self.mysql_password,
            database = self.database,
            charset='utf8'
        )
